package com.flight.trans.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flight.trans.R;
import com.flight.trans.bean.LeavePortWarehousingDetailBean.WarehousingDetailData.WarehousingMainInfoBean;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import java.util.List;

/**
 * 出港入库
 */
public class LevePortWarehousingInfoAdapter extends BaseRecyclerAdapter<WarehousingMainInfoBean> {

    private int currentPosition = -1;

    public LevePortWarehousingInfoAdapter(Context mContext, List<WarehousingMainInfoBean> mList , boolean isEditor) {
        super(mContext, mList);
        this.IsEditor = isEditor;
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_warehousing_info;
    }

    @Override
    protected void bindData(BaseViewHolder holder, WarehousingMainInfoBean data, int position) {
        RelativeLayout mRlContainerItem = holder.findViewById(R.id.mRlContainerItem);

        LinearLayout mLlContainerInfo = holder.findViewById(R.id.mLlContainerInfo);
        ImageView mIvAdd = holder.findViewById(R.id.mIvAdd);

        TextView mTvContainerNo = holder.findViewById(R.id.mTvContainerNo);
        TextView mTvCountWeight = holder.findViewById(R.id.mTvCountWeight);
        TextView mTvStorageArea = holder.findViewById(R.id.mTvStorageArea);

        // 设置隐藏、显示
        mIvAdd.setVisibility(data == null ? View.VISIBLE : View.GONE);
        mLlContainerInfo.setVisibility(data == null ? View.GONE : View.VISIBLE);

        if(data == null){
            mIvAdd.setVisibility(View.VISIBLE);
            mLlContainerInfo.setVisibility(View.GONE);

            setOnItemClickListener(mIvAdd , position);
        } else {
            if(IsEditor)
                setOnItemLongClickListener(mRlContainerItem , position);

            mIvAdd.setVisibility(View.GONE);
            mLlContainerInfo.setVisibility(View.VISIBLE);

            mTvContainerNo.setText("# " + data.getTransportCode());
            mTvCountWeight.setText(data.getNum() + " 件 / " + data.getWeight() + " KG");
            mTvStorageArea.setText(data.getWarehouseAreaName());

            mLlContainerInfo.setBackground(mContext.getDrawable(currentPosition == position ? R.drawable.shape_blue_20 : R.drawable.shape_blue_trans_20));
            mTvCountWeight.setTextColor(mContext.getColor(currentPosition == position ? R.color.white : R.color.color_blue_dark));
            mTvStorageArea.setTextColor(mContext.getColor(currentPosition == position ? R.color.white : R.color.color_blue_dark));

            setItemClickListener(mRlContainerItem, position);
        }
    }

    public void updateAdapter(List<WarehousingMainInfoBean> mList , int position){
        this.currentPosition = position ;
        updateAdapter(mList);
    }
}
